#include "LidarConfigurationOptions.h"

#include <iostream>
#include <map>
#include <variant>
#include <string>

#pragma region Init
LidarConfigurationOptions::LidarConfigurationOptions()
{
    _mapDefaultValues = { 
        {Data_Source_SrcType, LidarInputSourceType::ONLINE_LIDAR},
        {Data_SrcNet_MsopPort, (uint16_t)6699},
        {Data_SrcNet_DifopPort, (uint16_t)7788},
        {Data_SrcNet_RemoteIP,""},
        {Data_SrcNet_LocalIP,""},
        {Data_SrcNet_ManuType, LidarManufacturerType::RS_M1},
        {Data_Callback_DecType, LidarDecodeType::RAW},
        {Data_Callback_NoDelay, false},
        {Data_Decode_SampleVoxel, 0.05f},
        {Data_Decode_FiltMeanK, 50.0f},
        {Data_Decode_FiltThreshold, 1.0f},
        {Data_Decode_Transform, TransformParam()},
        {Data_Decode_CorrectionFile,""},
        {Data_SrcPcd_FilePath, ""}};
    _mapValues = _mapDefaultValues;
}

LidarConfigurationOptions::~LidarConfigurationOptions()
{
}
#pragma endregion

#pragma region Method
void LidarConfigurationOptions::SetValue(std::string key, ConfValueType value)
{
    if (_mapValues.find(key) != _mapValues.end())
    {
        _mapValues[key] = value;
        for (ParameterChangedNotify handler : _paramterChangedNotify)
        {
            handler(key, value);
        }
    }
}

ConfValueType LidarConfigurationOptions::GetValue(std::string key)
{
    if (_mapValues.find(key) != _mapValues.end())
    {
        return _mapValues[key];
    }
    return ConfValueType();
}

ConfValueType LidarConfigurationOptions::GetDefaultValue(std::string key)
{
    if (_mapDefaultValues.find(key) != _mapDefaultValues.end())
    {
        return _mapDefaultValues[key];
    }
    return ConfValueType();
}

bool LidarConfigurationOptions::addParameterChangedNotify(ParameterChangedNotify notify)
{
    _paramterChangedNotify.push_back(notify);
    return true;
}
#pragma endregion